package com.atmc.config;

import com.atmc.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple2;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @BelongsProject: SpringCloud1216
 * @BelongsPackage: com.atmc.config
 * @Author: chuyings
 * @CreateTime: 2022-11-18  12:51
 * @Version: 1.0
 */
@Configuration
public class PubSubStream {
    @Bean
    public Supplier<String> source(){
        return ()->{
            String message="from source";
            System.out.println("===========from source============");
            return message;
        };
    }

    @Bean
    public Function<User,User> transfer(){
        return user -> {
            System.out.println("transfer: "+user);
            return user;
        };
    }
    @Bean
    public Function<Tuple2<Flux<String>,Flux<String>>,Flux<String>> gather(){
        return tuple->{
            Flux<String> flux1=tuple.getT1();
            Flux<String> flux2=tuple.getT2();
            //整合一个flux
             Flux<String> merge = Flux.merge(flux1, flux2);
            return merge;
        };
    }
//
//    //Consumer声明一个消息消费者，sink1就对应sink-in-0
//    @Bean
//    public Consumer<String> sink() {
//        return message -> {
//            System.out.println("******************");
//            System.out.println("At Sink1");
//            System.out.println("******************");
//            System.out.println("Received message " + message);
//        };
//    }
}
